package com.xiexiaozhou.helper.api.utils;

import com.sun.org.apache.regexp.internal.RE;
import com.xiexiaozhou.helper.api.vo.Result;

public class ResultGenerator {

    private static final String DEFAULT_SUCCESS_MESSAGE = "SUCCESS";

    public static <T> Result<T> ok() {
        return new Result<T>().setStatus(Result.RESULT_CODE_SUCCESS).setMessage(DEFAULT_SUCCESS_MESSAGE);
    }

    public static <T> Result<T> ok(T data) {
        return new Result<T>().setStatus(Result.RESULT_CODE_SUCCESS).setData(data).setMessage(DEFAULT_SUCCESS_MESSAGE);
    }

    public static <T> Result<T> ok(T data, String message) {
        return new Result<T>().setStatus(Result.RESULT_CODE_SUCCESS).setData(data).setMessage(message);
    }

    public static Result<String> fail() {
        return new Result<String>().setStatus(Result.RESULT_CODE_INTERNAL_SERVER_ERROR).setMessage("未知错误，请联系系统管理员").setData("");
    }

    public static Result<String> fail(String data, String message) {
        return new Result<String>().setStatus(Result.RESULT_CODE_INTERNAL_SERVER_ERROR).setData(data).setMessage(message);
    }

    public static Result<String> fail(int code, String data, String message) {
        return new Result<String>().setStatus(code).setData(data).setMessage(message);
    }

    public static Result<String> fail404(String requestURI) {
        return new Result<String>().setStatus(Result.RESULT_CODE_NOT_FOUND).setData("请求路径" + requestURI).setMessage("未存在请求资源");
    }

    public static Result<String> fail500(String exceptionMsg) {
        return new Result<String>().setStatus(Result.RESULT_CODE_INTERNAL_SERVER_ERROR).setData("错误信息：" + exceptionMsg).setMessage("未知错误请联系系统管理员");
    }

    public static Result<String> unauthorized(String exceptionMsg) {
        return new Result<String>().setStatus(Result.RESULT_CODE_UNAUTHORIZED).setData("错误信息：" + exceptionMsg).setMessage("认证失败");
    }
}
